/*
 * $Id: MessageSourceAccessHelper.java 50 2013-06-28 08:44:15Z gabakyan $
 * $Author: gabakyan $
 * $Revision: 50 $
 * $Date: 2013-06-28 08:44:15 +0000 (Fri, 28 Jun 2013) $
 *
 * Copyright (c) 2013 Supply Chain Intelligence (SCI), Inc.
 * http://www.scintelligence.com/, Email: info@scintelligence.com
 * All rights reserved.
 *
 * This file is part of Logistics Map.
 *
 * Logistics Map is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * Logistics Map is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Logistics Map.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.sci.logisticsmap.support;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.stereotype.Component;

import java.util.Locale;

/**
 * The class {@code MessageSourceAccessHelper} provides methods for accessing messages.
 *
 * @author gabakyan@gmail.com (Last modified by $Author: gabakyan $)
 * @version $Revision: 50 $
 */
@Component
public class MessageSourceAccessHelper {
    /**
     * The message source accessor.
     */
    @Autowired
	private MessageSourceAccessor messageSourceAccessor;

    /**
     * Retrieves the message.
     *
     * @param code The code.
     *
     * @return The message.
     */
	public String getMessage(String code) {
		return getMessage(code, null);
	}

    /**
     * Retrieves the message.
     *
     * @param code The code.
     * @param locale The locale.
     *
     * @return The message.
     */
	public String getMessage(String code, Locale locale) {
		return getMessage(code, null, locale);
	}

    /**
     * Retrieves the message.
     *
     * @param code The code.
     * @param arg The argument for the message, or {@code null} if none.
     * @param locale The locale.
     *
     * @return The message.
     */
	public String getMessage(String code, Object arg, Locale locale) {
		return getMessage(code, new Object[] {arg}, locale);
	}

    /**
     * Retrieves the message.
     *
     * @param code The code.
     * @param args The arguments for the message, or {@code null} if none.
     * @param locale The locale.
     *
     * @return The message.
     */
	public String getMessage(String code, Object[] args, Locale locale) {
		return messageSourceAccessor.getMessage(code, args, locale);
	}
}
